package com.meiyu.live.util;

import android.content.Context;
import android.util.DisplayMetrics;

/**
 * @author Joosun
 * @since 2013-7-26
 */
public class DisplayUtils
{
	public static int pixelToDp(final Context pContext, final int pPixels)
	{
		final float density = pContext.getResources().getDisplayMetrics().density;

		return (int) ((pPixels / density) + 0.5);
	}

	public static int dpToPixel(final Context pContext, final int pDp)
	{
		final float density = pContext.getResources().getDisplayMetrics().density;

		return (int) ((pDp * density) + 0.5f);
	}

	/**
	 * 获取屏幕尺寸
	 * @param pContext
	 * @return 数组，int[0]宽度，int[1]高度
	 */
	public static int[] getScreenSize(final Context pContext)
	{
		final DisplayMetrics displayMetrics = pContext.getResources().getDisplayMetrics();
		int[] size = new int[2];
		size[0]=displayMetrics.widthPixels;
		size[1]=displayMetrics.heightPixels;
		return size;
	}
}